


export const newsimg = async (files: any) => {
  let newsarr: string[] = [];
  const uploadPromises: Promise<void>[] = [];

  files.forEach((e: any) => {
    const uploadPromise = new Promise<void>((resolve, reject) => {
      uni.uploadFile({
        url: 'http://10.34.91.156/upload',
        filePath: e.path,
        name: 'image',
        success: (uploadRes) => {
          const data = JSON.parse(uploadRes.data);
          newsarr.push(data.data);
          resolve();
        },
        fail: (uploadErr) => {
          console.error('上传失败', uploadErr);
          reject(uploadErr);
        },
      });
    });

    uploadPromises.push(uploadPromise);
  });

  try {
    await Promise.all(uploadPromises); // 等待所有上传完成
    return newsarr
  } catch (error) {
    console.error('上传文件出错', error);
  }
};